#include <QApplication>
#include <QAbstractItemModel>
#include <QAbstractItemView>
#include <QItemSelection>
#include <QDirModel>
#include <QTreeView>
#include <QListView>
#include <QTableView>
#include <QSplitter>

int main(int argc, char* argv[])
{
    QApplication app(argc,argv);

    QDirModel model;     //创建模型;   QDirModel用于展示文件系统目录结构的模型类

    QTreeView tree;
    QListView list;
    QTableView table;

    //视图设置模型
    tree.setModel(&model);
    list.setModel(&model);
    table.setModel(&model);

    //设置视图对象的选择方式为多选，list和table选择方式同tree
     tree.setSelectionMode(QAbstractItemView::MultiSelection);
     //list.setSelectionMode(QAbstractItemView::MultiSelection);
     list.setSelectionMode(tree.selectionMode());
     table.setSelectionMode(tree.selectionMode());

    //树视图双击信号发射后，根据QModelindex索引，刷新列表及表格的内容
    QObject::connect(&tree,SIGNAL(doubleClicked(QModelIndex)),&list,SLOT(setRootIndex(QModelIndex)));
    QObject::connect(&tree,SIGNAL(doubleClicked(QModelIndex)),&table,SLOT(setRootIndex(QModelIndex)));

    QSplitter *splitter=new QSplitter;
    splitter->addWidget(&tree);
    splitter->addWidget(&list);
    splitter->addWidget(&table);
    splitter->setWindowTitle(QString("模型/视图"));

    splitter->show();




    return app.exec();
}
